{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "分词结果: []\n",
      "词性标注结果: []\n",
      "依存句法分析结果: \n",
      "语义角色标注结果: []\n",
      "句子中谓词的数量： 0\n",
      "句子中的谓词: []\n",
      "句子中谓词的索引 \n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from pyltp import Segmentor\n",
    "from pyltp import Postagger\n",
    "from pyltp import Parser\n",
    "from pyltp import SementicRoleLabeller\n",
    "LTP_DIR='ltp_data_v3.4.0'\n",
    "cws_model_path=os.path.join(LTP_DIR,\"cws.model\")\n",
    "segmentor=Segmentor(cws_model_path)\n",
    "words = segmentor.segment(\"原告在昨天正式向法院提起诉讼，将与后天开庭\")\n",
    "print('分词结果:',list(words))\n",
    "pos_model_path = os.path.join(LTP_DIR,\"pos.model\")\n",
    "postagger = Postagger(pos_model_path)\n",
    "postags = postagger.postag(words)\n",
    "print('词性标注结果:',list(''.join(postags)))\n",
    "par_model_path = os.path.join(LTP_DIR,\"parser.model\")\n",
    "parser = Parser(par_model_path)\n",
    "arcs = Parser(par_model_path)\n",
    "arcs = parser.parse(words,postags)\n",
    "print('依存句法分析结果:',\" \".join(\"%d:%s\" % (arc[0],arc[1]) for arc in arcs))\n",
    "lab_model_path=os.path.join(LTP_DIR,\"pisrl_win.model\")\n",
    "labeller=SementicRoleLabeller(lab_model_path)\n",
    "roles=labeller.label(words,postags,arcs)\n",
    "print('语义角色标注结果:',roles)\n",
    "print('句子中谓词的数量：',len(roles))\n",
    "verbs=[words[role[0]] for role in roles]\n",
    "print('句子中的谓词:',verbs)\n",
    "print('句子中谓词的索引','\\t'.join('%d' % role[0] for role in roles))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
